package edu.nf.vac.api.controller;


import edu.nf.vac.announcement.dao.AnnouncementDTO;
import edu.nf.vac.announcement.dao.AnnouncementPageDTO;
import edu.nf.vac.announcement.service.AnnouncementService;
import edu.nf.vac.api.vo.ResultVO;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LQJ
 * @date 2022/3/30
 */
@Api(tags = "公告服务接口")
@RestController
@RequestMapping("/api/v1")
public class AnnouncementController extends BaseController {

    @DubboReference(interfaceClass = AnnouncementService.class,
            version="1.0.0",check = false)
    private AnnouncementService service;

    @GetMapping("/announcement/list")
    @ApiOperation(value="查询公告列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name="page", value="页码", required=true, dataTypeClass=Integer.class, paramType="query"),
            @ApiImplicitParam(name="limit", value="每页显示记录数", required=true, dataTypeClass=Integer.class, paramType="query")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "返回公告列表集合", response = ResultVO.class),
            @ApiResponse(code = 500, message = "服务异常")
    })
    public ResultVO<List<AnnouncementDTO>> listAnnouncement(int page, int limit) {
        AnnouncementPageDTO pageDTO = service.listAnnouncement(page, limit);
        return pageResult(pageDTO.getTotal(), pageDTO.getList());
    }

    @GetMapping("/announcement/{id}")
    @ApiOperation(value="根据ID查看公告信息", httpMethod = "GET")
    @ApiImplicitParam(name="id", value="公告ID", required=true, dataTypeClass=Integer.class, paramType="path")
    @ApiResponses({
            @ApiResponse(code = 200, message = "返回公告信息", response = ResultVO.class),
            @ApiResponse(code = 500, message = "服务异常")
    })
    public ResultVO<AnnouncementDTO> getAnnouncement(@PathVariable("id") int id) {
        AnnouncementDTO dto = service.getAnnouncementById(id);
        return success(dto);
    }
}
